package com.five.student.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class AdminController {

    // 访问 /admin/index 时，返回 templates/admin/index.html
    @GetMapping("/admin/index")
    public String adminIndex(HttpSession session, Model model) {
        // 从 session 获取当前用户
        Object user = session.getAttribute("user");
        if (user == null) {
            // 未登录，重定向到登录页面
            return "redirect:/login";
        }
        // 把用户信息传到前端页面
        model.addAttribute("user", user);
        return "admin/index";
    }
}
